package com.basaji.dao.impl;

import java.io.Serializable;
import java.util.List;

import com.basaji.dao.IBaseDao;
import com.basaji.dao.manager.PojoManager;
import com.basaji.domain.pojo.BaseObject;

public class BaseDao implements IBaseDao {
	
	protected boolean CACHE;

	protected PojoManager pojoManager;
	

	@SuppressWarnings("unchecked")
	public void delete(BaseObject t) throws Exception {
		pojoManager.delete(t);

	}

	public BaseObject get(Class<? extends BaseObject> clazz, Object id)
			throws Exception {
		if (id instanceof Serializable) {
			return pojoManager.getOneByID(clazz, (Serializable) id);
		} else {
			return pojoManager.getOneByID(clazz, id.toString());
		}
	}


	public void saveOrUpdate(BaseObject basePojo) throws Exception {
		pojoManager.saveOrUpdate(basePojo);

	}

	public PojoManager getPojoManager() {
		return pojoManager;
	}

	public void setPojoManager(PojoManager pojoManager) {
		this.pojoManager = pojoManager;
	}

	public void save(BaseObject t) throws Exception {
		pojoManager.save(t);
		
	}

	public void update(BaseObject t) throws Exception {
		pojoManager.update(t);
		
	}

	@Override
	public <T> List<T> getList(String hql, Object[] values, int start, int size)
			throws Exception {
		return pojoManager.getList(hql, values, start, size);
	}

	@Override
	public int getCount(String hql, Object[] values) throws Exception {
		return pojoManager.getIntCount(hql, values);
	}

	
}
